<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="<%=basePath%>js/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<style>
.topBar
{
	width:100%;
	background-color: black;
	color:white;
	height:30px;
	position:absolute;
	top:0px;
	left:0px;
}
</style>
</head>
<body>
<div class="topBar">
<div style="float:right;padding-right: 100px;" id="loginField">
<c:if test="${user_session==null }">
用户名:<input type="text" name="user.name" id="name">
密码:<input type="password" name="user.password" id="password">
<input type="button" value="登录" onclick="login();">
</c:if>
<c:if test="${user_session!=null }">
${user_session.name }
<button onclick="logout();">登出</button>
</c:if>
</div>
</div>
<br>
</body>
<script>

//登录
function login()
{
	$.ajax({
		url:"userAction!login.action",
		data:{"user.name":$("#name").val(),"user.password":$("#password").val()},
		dataType:"json",
		success:function(mess)
		{
			if(mess.result==0)alert("用户与密码不对应");
			else
			{
				alert("登录成功");
				$("#loginField").html(mess.name+"<button onclick='logout();'>登出</button>");
			}
					
		}
	});
}

//登出

function logout()
{
	$.ajax({
		url:"userAction!logout.action",		
		success:function(mess)
		{
			$("#loginField").html("用户名:<input type='text' name='user.name' id='name'>"+
					"密码:<input type='password' name='user.password' id='password'>"+
			"<input type='button' value='登录' onclick='login();'>")
		}
	});
}

</script>
</html>